<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>应用日志</title>
    <link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
    <script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script type="text/javascript" src="D:\Project\FileTest\Download.log"></script>
    <a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">

<div data-options="region:'north',split:false" style="height:25px;width:100%;" >
    <span id="appName"></span>&nbsp;&nbsp;
    <span id="appCnname"></span>&nbsp;&nbsp;
    <span id="action"></span>&nbsp;&nbsp;
    <span id="status"></span>&nbsp;&nbsp;
    <span>日志刷新间隔(秒)：</span>
    <span><input class="easyui-numberbox" value="5"  data-options="min:1,precision:0" id="refreshTime" style="width: 80px"></input></span>
</div>
<div data-options="region:'center',split:false" style="height:100%;:width:100%;">
    <tr>
        <td width="100%" aria-colspan="10"><input class="easyui-textbox" data-options="multiline:true" type="textarea"
                                                id="logFile"
                                                style="width: 100%;height: 100%"></input></td>
    </tr>
</div>
<div data-options="region:'south',split:false" style="height:10%;width:100%;">
    <div class="esaas-info-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeForm()" style="width:90px">&nbsp;关&nbsp;闭&nbsp;</a>
    </div>
</div>

</body>
<script>
    var head = 0;
    var file = "";
    var appName = $.getUrlParam("appName")
    var appCnname = $.getUrlParam("appCnname")
    var action = $.getUrlParam("action")
    var status = $.getUrlParam("status")
    var isFirst = true;
    var fileNotCompleted = true;
    $(function (){
        var color;
        $('#appName').html("应用名称："+appName)
        $('#appCnname').html(" 应用中文名称："+appCnname)
        switch (action){
            case "start":
                action = "应用启动";
                break;
            case "restart":
                action = "应用重启";
                break;
            case "stop":
                action = "应用停止";
                break;
        }
        switch (status){
            case "Succeed":
                status = "执行成功";
                color = "green";
                break;
            default:
                status = "执行失败";
                color = "red";
        }
        $('#action').html(" 应用运维指令："+action)
        $('#status').html("状态："+status)
        document.getElementById("status").style.color=color;

        timeRefresh();
    })

    function timeRefresh(first) {
        if (!first) {
            getLog();
        }
        if(fileNotCompleted){
            var refreshTime = $('#refreshTime').textbox("getValue") ;
            window.setTimeout("timeRefresh()", refreshTime * 1000);
        }

    }

    function getLog(){
        var appDeployId = $.getUrlParam("appDeployId");
        var fileNmae = "catalina*out";
        $.restfulGet("../../api/sys/deploy/info/file/download/"+appDeployId+"/"+fileNmae+"/"+head+"/"+isFirst,null,function (data){
            isFirst =false;
            if ("" == data.rows.file){
                $('#logFile').textbox("setValue","此日志无内容")
            }else {
                file = data.rows.file+file;
                $('#logFile').textbox("setValue",file)
                head = data.rows.head;
                if (head==1){
                    file = "日志内容全部加载完成,停止刷新！\n"+file;
                    $('#logFile').textbox("setValue",file)
                    fileNotCompleted = false;
                }
            }
        })
    }
    function closeForm() {
        $.messager.confirm('确认','您确认想要关闭页面吗？',function(r){
            if (r){
                window.parent.close();
            }
        });
    }

</script>
</html>